{% extends "base_generic.html" %}

{% block title %}{{ author.first_name }} {{ author.last_name }}{% endblock %}

{% block content %}
  <div class="page-header">
    <h1>{{ author.first_name }} {{ author.last_name }}</h1>
  </div>

  <div class="row">
    <div class="col-md-6">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title">Author Information</h3>
        </div>
        <div class="panel-body">
          <p><strong>Name:</strong> {{ author.first_name }} {{ author.last_name }}</p>
          
          {% if author.date_of_birth %}
            <p><strong>Date of Birth:</strong> {{ author.date_of_birth }}</p>
          {% endif %}
          
          {% if author.date_of_death %}
            <p><strong>Date of Death:</strong> {{ author.date_of_death }}</p>
          {% endif %}
          
          {% if author.date_of_birth and author.date_of_death %}
            <p><strong>Age at Death:</strong> 
              {{ author.date_of_death.year|add:author.date_of_birth.year|add:"-1" }} years old
            </p>
          {% elif author.date_of_birth %}
            <p><strong>Current Age:</strong> 
              {% now "Y" as current_year %}
              {{ current_year|add:author.date_of_birth.year|add:"-1" }} years old
            </p>
          {% endif %}
        </div>
      </div>
    </div>

    <div class="col-md-6">
      <div class="panel panel-info">
        <div class="panel-heading">
          <h3 class="panel-title">Books</h3>
        </div>
        <div class="panel-body">
          {% if author.book_set.all %}
            <div class="list-group">
              {% for book in author.book_set.all %}
                <a href="{{ book.get_absolute_url }}" class="list-group-item">
                  <h4 class="list-group-item-heading">{{ book.title }}</h4>
                  <p class="list-group-item-text">{{ book.summary|truncatewords:15 }}</p>
                  {% if book.genre.all %}
                    <p>
                      {% for genre in book.genre.all %}
                        <span class="label label-primary">{{ genre.name }}</span>
                        {% if not forloop.last %} {% endif %}
                      {% endfor %}
                    </p>
                  {% endif %}
                </a>
              {% endfor %}
            </div>
          {% else %}
            <p class="text-muted">This author has no books recorded.</p>
          {% endif %}
        </div>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-md-12">
      <a href="{% url 'authors' %}" class="btn btn-default">
        <span class="glyphicon glyphicon-arrow-left"></span> Back to author list
      </a>
      
      {% if perms.catalog.can_mark_returned %}
        <a href="{% url 'author-update' pk=author.pk %}" class="btn btn-primary">
          <span class="glyphicon glyphicon-edit"></span> Edit author
        </a>
        <a href="{% url 'author-delete' pk=author.pk %}" class="btn btn-danger">
          <span class="glyphicon glyphicon-trash"></span> Delete author
        </a>
      {% endif %}
    </div>
  </div>

{% endblock %} 